package arithmetic;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @program: javaLearn
 * @description: 罗马数字
 * @author: renhai
 * @Date ：2022/4/8 22:40
 **/
public class romanNumerals {

    /**
     *
     * @param s
     * @return
     */
    /**
     * public int romanToInt(String s) {
     * int ans = 0;
     * int n = s.length();
     * for (int i = 0; i < n; ++i) {
     * int value = symbolValues.get(s.charAt(i));
     * if (i < n - 1 && value < symbolValues.get(s.charAt(i + 1))) {
     * ans -= value;
     * } else {
     * ans += value;
     * }
     * }
     * return ans;
     * }
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String num = in.next();

        HashMap<Character, Integer> nums = new HashMap<>();
        nums.put('I', 1);
        nums.put('V', 5);
        nums.put('X', 10);
        nums.put('L', 50);
        nums.put('C', 100);
        nums.put('D', 500);
        nums.put('M', 1000);
        int sum = 0;
        char[] numAll = num.toCharArray();

        for (int i = 0; i < num.length(); i++) {
            if (i < num.length() - 1 && nums.get(numAll[i]) < nums.get(numAll[i + 1])) {
                sum -= nums.get(numAll[i - 1]);
            } else {
                sum += nums.get(numAll[i]);
            }
        }
        System.out.println(sum);


    }
}
